package ar.edu.utn.frsf.cidisi.ginet.generation.pnml2wscdl.elementstemplate;

import org.eclipse.emf.common.util.EList;
import org.pnml.tools.epnk.pnmlcoremodel.Page;
import org.w3._2005._10.cdl.CdlFactory;
import org.w3._2005._10.cdl.TChoice;
import org.w3._2005._10.cdl.TChoreography;
import org.w3._2005._10.cdl.TWorkunit;

public class IfWSCDL extends WSCDLStructure{
	
	public IfWSCDL(Page page, TChoreography choreography){
		this.page = page;
		this.choreography = choreography;
	}
	
	public TWorkunit createWSCDLElement(){
		TWorkunit tWorkunit = CdlFactory.eINSTANCE.createTWorkunit();
		
		tWorkunit.setName("if");
		
		EList<Page> pages1 = this.getPages(page);
	
		if(pages1.size() >2){
			TChoice choice = CdlFactory.eINSTANCE.createTChoice();
			TWorkunit workunit = CdlFactory.eINSTANCE.createTWorkunit();
			workunit.setName("ifTrue");
			this.addTo(workunit, this.createPackageWscdl(pages1.get(0), this.choreography));

			TWorkunit workunit1 = CdlFactory.eINSTANCE.createTWorkunit();
			workunit1.setName("ifFalse");
			this.addTo(workunit1, this.createPackageWscdl(pages1.get(1), this.choreography));
			
			choice.getWorkunit().add(workunit);
			choice.getWorkunit().add(workunit1);
			tWorkunit.setChoice(choice);
		}else{
			TWorkunit workunit = CdlFactory.eINSTANCE.createTWorkunit();
			workunit.setName("if");
			this.addTo(workunit, this.createPackageWscdl(pages1.get(0), this.choreography));
			tWorkunit.setWorkunit(workunit);
		}

		return tWorkunit;		
	}

}
